先查看包包
# cogs/money.py
# 略
@bot.command()
async def bag(ctx):
    await open_account(ctx.author)
    user = ctx.author    
    users = await get_bank_data()
try:
    bag = users[str(user.id)]["bag"]
except:
    bag = []
em = discord.Embed(title = "Bag", color = 0xFF5733)
em.set_thumbnail(url = user.avatar_url)
for item in bag:
    name = item["item"]
    amount = item["amount"]
    
    em.add_field(name = name, value = amount)
    
await ctx.send(embed = em)
建立起買東西的式子
async def buySomething(user, itemName, amount):
    name = None
    itemName = itemName.lower()
    for item in shop:
        Item_Name = item["name"].lower()
        if Item_Name == itemName:
            name = Item_Name
            price = item["price"]
            break
if name == None:
    return [False, 1]
cost = price * amount
    
users = await get_bank_data()
bal = await update_bank(user)
    
if bal[0] < cost :
    return [False , 2] 
@commands.command()
# amount = 1為默認
async def buy(self, ctx, item, amount = 1):
    pass
await open_account(ctx.author)
    
res = await buy_this(ctx.author, item, amount)
    
if res[0] == False :
    if res[1] == 1 :
        await ctx.send("沒有這個東西喔")
        return
    if res[1] == 2 :
        await ctx.send(f"你的錢包裡沒有足夠的錢去買 {item}")
        return
        
await ctx.send(f"你買到了 {amount} x{item}")
- 到這邊應該是沒有什麼問題,這時候你點開json檔,發現啥麼都沒出現......